package br.gov.ms.tce.cjur.convert;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

import br.com.caelum.stella.format.CPFFormatter;


@FacesConverter("cpfConverter")
public class CPFConverter implements Converter {

    

    public Object getAsObject(FacesContext context, UIComponent component, String value) {
    	CPFFormatter f = new CPFFormatter();
     return f.unformat(value);
    }

    public String getAsString(FacesContext context, UIComponent component, Object object) {
    	if(object.equals(""))
    		return "";
    	
    	CPFFormatter f = new CPFFormatter();
        return f.format((String)object);
    }
}
